package com.qf.service.impl;

import com.qf.dao.CityMapper;
import com.qf.pojo.City;
import com.qf.service.CityService;
import com.qf.vo.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class CityServiceImpl implements CityService {

    @Autowired
    CityMapper cityMapper;
    @Override
    public BaseResult findAllCity(int id) {
        BaseResult baseResult = new BaseResult();
        List<City> cityList= cityMapper.findAllCity(id);
        baseResult.setInfo(cityList);
        return baseResult;
    }

    @Override
    public BaseResult viewCity(int getid, int backid) {
        BaseResult baseResult = new BaseResult();
        City getCity = cityMapper.findCityById(getid);
        City backCity = cityMapper.findCityById(backid);
        if(getCity==null || backCity==null ){
            baseResult.setCode(10000);
            return baseResult;
        }
        ArrayList<City> arrayList = new ArrayList<>();
        arrayList.add(getCity);
        arrayList.add(backCity);
        baseResult.setInfo(arrayList);
        baseResult.setCode(1);
        return baseResult;
    }

//    @Override
//    public BaseResult viewCity(int id) {
//        BaseResult baseResult = new BaseResult();
//        City cityById = cityMapper.findCityById(id);
//        if(cityById==null){
//            baseResult.setCode(10000);
//            return baseResult;
//        }
//        baseResult.setCode(1);
//        baseResult.setInfo(cityById);
//        return baseResult;
//    }
}
